package com.young.cms.model.enums;


/**
 * 字段类型
 * 常用的
 *
 * @author wangjy
 * @date 2022/03/19 23:52:40
 */
public enum EColumnTypeEnum {

    BIGINT("bigint", "bigint", "Long")
    , TINYINT("tinyint", "tinyint", "Integer")
    , INT("int", "int", "Integer")
    , DOUBLE("double", "double", "Double")
    , FLOAT("float", "float", "Float")
    , DECIMAL("decimal", "decimal", "BigDecimal")
    , NUMERIC("numeric", "numeric", "BigDecimal")

    , BOOLEAN("boolean", "boolean", "Boolean")

    , DATE("date", "date", "Date")
    , DATETIME("datetime", "datetime", "Date")
    , TIME("time", "time", "Date")
    , TIMESTAMP("timestamp", "timestamp", "Date")

    , TEXT("text", "text", "String")
    , CHAR("char", "char", "Char")
    , VARCHAR("varchar", "varchar", "String")
    ;

    private String type;
    private String text;
    private String javaType;

    EColumnTypeEnum(String type, String text, String javaType) {
        this.type = type;
        this.text = text;
        this.javaType = javaType;
    }

    /**
     * 是否有长度限制的字符类型
     * @return
     */
    public boolean isLengthLimitStringType() {
        return this == CHAR || this == VARCHAR;
    }

    /**
     * 是否数字类型
     * @return
     */
    public boolean isNumberType() {
        return this == BIGINT || this == TINYINT || this == INT || this == DOUBLE || this == FLOAT || this == DECIMAL || this == NUMERIC;
    }

    /**
     * 是否时间类型
     * @return
     */
    public boolean isDateType() {
        return this == DATE || this == DATETIME || this == TIME || this == TIMESTAMP;
    }

    public static EColumnTypeEnum ofOrDefault(String type) {
        if (type != null) {
            for (EColumnTypeEnum e : EColumnTypeEnum.values()) {
                if (e.type.equalsIgnoreCase(type)) {
                    return e;
                }
            }
        }
        return VARCHAR;
    }

    public String getType() {
        return type;
    }

    public String getText() {
        return text;
    }

    public String getJavaType() {
        return javaType;
    }
}
